<?php

namespace app\api\controller;

use hg\apidoc\annotation as Apidoc;
use hg\apidoc\annotation\Param;
use hg\apidoc\annotation\Query;
use hg\apidoc\annotation\Returned;
use hg\apidoc\annotation\Header;
use app\BaseController;
use think\facade\View;
use think\facade\Db;
use think\response\Json;
/**
 * 聊天提示词_会员
 *
 * api-ChatPromptMember
 *
 * @Apidoc\Title("聊天提示词_会员")
 * @Apidoc\Group("api")
 */
class ChatPromptMember extends Auth
{
    /**
     * list
     * @Apidoc\Title("收藏列表")
     */
    public function list()
    {
        $ids = \app\common\model\ChatPromptMember::where('member_id', $this->request->uid)
            ->order('id','desc')->column('chat_prompt_id');
        $data = [];
        if($ids){
            $data = \app\common\model\ChatPrompt::where('id', 'in', $ids)
                ->select();
        }
        return success('', [
            'ids' => $ids,
            'data' => $data
        ]);
    }


    /**
     * add
     * @Apidoc\Title("添加收藏")
     */
    public function add()
    {
        $id = input('id');
        $data = [
            'chat_prompt_id' => $id,
            'member_id' => $this->request->uid
        ];
        \app\common\model\ChatPromptMember::create($data);
        $ids = \app\common\model\ChatPromptMember::where('member_id', $this->request->uid)
            ->order('id','desc')->column('chat_prompt_id');
        $data = [];
        if($ids){
            $data = \app\common\model\ChatPrompt::where('id', 'in', $ids)
                ->select();
        }
        return success('', [
            'ids' => $ids,
            'data' => $data
        ]);

    }

    /**
     * delete
     * @Apidoc\Title("删除收藏")
     */
    public function delete()
    {
        $id = input('id');
        $where = [
            'chat_prompt_id' => $id,
            'member_id' => $this->request->uid
        ];
        \app\common\model\ChatPromptMember::destroy(function($query) use ($where){
            $query->where($where);
        });
        $ids = \app\common\model\ChatPromptMember::where('member_id', $this->request->uid)
            ->order('id','desc')->column('chat_prompt_id');
        $data = [];
        if($ids){
            $data = \app\common\model\ChatPrompt::where('id', 'in', $ids)
                ->select();
        }
        return success('', [
            'ids' => $ids,
            'data' => $data
        ]);
    }
}
